package zhouzhouyongche.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import zhouzhouyongche.model.Day;
import zhouzhouyongche.model.Month;

@Repository
public class MonthDao extends HibernateDao<Month> {
	
	public Month getOrAdd(int month) {
		Month result = null;
		String hql = "from Month as m where m.month = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, month);
		List monthList = q.list();
		if (monthList.size() == 0) {
			Month monthObj = new Month();
			monthObj.setMonth(month);
			this.save(monthObj);
			
			String _hql = "from Month as m where m.month = ?";
			Query _q = getCurrentSession().createQuery(_hql);
			_q.setInteger(0, month);
			result = (Month)q.list().get(0);
		} else {
			result = (Month)monthList.get(0);
		}
		return result;
	}
}
